﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAO;
namespace BUS
{
    public class HanhKhach_BUS
    {
        #region truy van du lieu
        //Các hàm truy xuất dữ liệu
        public static List<HanhKhach_DTO> layDanhSachHanhKhach()
        {
            return HanhKhach_DAO.layDanhSachHanhKhach();
        }
        public static HanhKhach_DTO layHanhKhachTheoMaHK(string maHK)
        {
            if (HanhKhach_DAO.kiemTraMaHK(maHK))
                return HanhKhach_DAO.layHanhKhachTheoMaHK(maHK);
            return null;
        }
        public static List<HanhKhach_DTO> layHanhKhachTheoHoTen(string hoTen)
        {
            return HanhKhach_DAO.layHanhKhachTheoHoTen(hoTen);
        }
        public static HanhKhach_DTO layHanhKhachTheoCMND(string cMND)
        {
            return HanhKhach_DAO.layHanhKhachTheoCMND(cMND);
        }

        #endregion

        #region Thao tac insert, update, delete
        //Các hàm thao tác với cơ sở dữ liệu
        public static int themHanhKhach(HanhKhach_DTO hanhKhach)
        {
            if (HanhKhach_DAO.kiemTraMaHK(hanhKhach.MaHK))
                return 2;
            return HanhKhach_DAO.themHanhKhach(hanhKhach)?1:0;
        }
        public static bool xoaHanhKhach(HanhKhach_DTO hanhKhach)
        {
            if (HanhKhach_DAO.kiemTraMaHK(hanhKhach.MaHK))
            {
                Ve_DTO ve = Ve_BUS.layVeTheoMaHK(hanhKhach.MaHK); //muon xoa hanh khach phai xoa ve truoc
                if (ve != null)
                {
                    Ve_BUS.xoaVe(ve);
                }
                    
                return HanhKhach_DAO.xoaHanhKhach(hanhKhach);
            }
            return false;
        }
        public static bool suaHanhKhach(HanhKhach_DTO hanhKhach)
        {
            if (HanhKhach_DAO.kiemTraMaHK(hanhKhach.MaHK))
            {
                return HanhKhach_DAO.suaHanhKhach(hanhKhach);
            }
            return false;
        }
        #endregion
    }
}
